package com.oocl.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.exception.MyException;
import com.oocl.pojo.Food;
import com.oocl.service.FoodService;
import com.oocl.service.impl.FoodServiceImpl;
import com.oocl.util.RequestUtil;

/**
 * Servlet implementation class FoodList4AjaxServlet
 */
public class FoodList4AjaxServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 String icnum = (String) request.getSession().getAttribute("icnum");
		 FoodService fSer = new FoodServiceImpl();
		 try {
			List<Food> list = fSer.loadFoodsByIcnum(icnum);
			System.out.print("FoodList4AjaxServlet list:"+list.size());
            String dataJson = RequestUtil.wrapToJson(list);
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().write(dataJson);
		} catch (MyException e) {
			throw e;
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
